Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




index( ) FUNCTION


The index( ) Function is used to return the first occurrence of an element in the List.


Let us say, we have a List that contains three names, 'Mohan', 'Kriti' and 'Salim'. And we want to find the location of 'Kriti'.


Example :


x = ["Mohan", "Kriti", "Salim"]
y = x.index("Kriti")
print("The position of Kriti is ",y)


Output :



  The position of Kriti is 1

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the List,


java_Collections

Now, if we see the above diagram, 'Kriti' resides at position/index '1'.


And the 'index( )' Function is used to find the position of 'Kriti'.


y = x.index("Kriti")

And we get the below output,


The position of Kriti is 1